home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 51 / Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso / -in_the_mag- / workbench / term_4.8 / extras / source / gtlayout-source.lha / LT_LockWindow.c < prev    next >
C/C++ Source or Header  |  1997-05-08  |  6KB  |  295 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1997 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #include "Assert.h"
  15.  
  16.  
  17. /*****************************************************************************/
  18.  
  19.  
  20. VOID
  21. LTP_DeleteWindowLock(LockNode *Node)
  22. {
  23.     struct Window *Window = Node->Window;
  24.  
  25.     Remove((struct Node *)Node);
  26.  
  27.     if(Window->MinWidth == Window->MaxWidth && Window->MinHeight == Window->MaxHeight && Window->Width == Window->MaxWidth && Window->Height == Window->MaxHeight)
  28.         WindowLimits(Window,Node->MinWidth,Node->MinHeight,Node->MaxWidth,Node->MaxHeight);
  29.  
  30.     EndRequest(&Node->Requester,Window);
  31.  
  32.     if(V39)
  33.         SetWindowPointerA(Window,NULL);
  34.     else
  35.         ClearPointer(Window);
  36.  
  37.     ModifyIDCMP(Window,Node->OldIDCMPFlags);
  38.  
  39.     FreeMem(Node,sizeof(LockNode));
  40. }
  41.  
  42.  
  43. /*****************************************************************************/
  44.  
  45.  
  46. /****** gtlayout.library/LT_LockWindow ******************************************
  47. *
  48. *   NAME
  49. *    LT_LockWindow -- Block user access to a window.
  50. *
  51. *   SYNOPSIS
  52. *    LT_LockWindow(Window);
  53. *                    A0
  54. *
  55. *    VOID LT_LockWindow(struct Window *);
  56. *
  57. *   FUNCTION
  58. *    The window will get a wait mouse pointer attached and a blank
  59. *    Requester, preventing any user gadgets from getting used. The
  60. *    window minimum and maximum sizes are set to the current window
  61. *    size so the user will be unable to resize the window or click
  62. *    on the zoom gadget.
  63. *
  64. *    This routine nests, multiple calls to LT_LockWindow() using the
  65. *    same window will increment a usage counter, so exactly the
  66. *    same number of calls to LT_UnlockWindow() will be required to
  67. *    unlock the window.
  68. *
  69. *   INPUTS
  70. *    Window - Pointer to window structure; passign NULL is harmless.
  71. *
  72. *   RESULT
  73. *    none
  74. *
  75. *   NOTES
  76. *    Do not close the window you have locked unless all the
  77. *    outstanding locks are freed or memory will be lost which
  78. *    can never be reclaimed. Before you close the window,
  79. *    call gtlayout.library/LT_DeleteWindowLock.
  80. *
  81. *   SEE ALSO
  82. *    gtlayout.library/LT_DeleteWindowLock
  83. *
  84. ******************************************************************************
  85. *
  86. */
  87.  
  88. VOID LIBENT
  89. LT_LockWindow(REG(a0) struct Window *window)
  90. {
  91.     if(window)
  92.     {
  93.         LockNode    *lockNode;
  94.         BOOL          found;
  95.  
  96.         found = FALSE;
  97.  
  98.         ObtainSemaphore(<P_LockSemaphore);
  99.  
  100.         SCANLIST(<P_LockList,lockNode)
  101.         {
  102.             if(lockNode->Window == window)
  103.             {
  104.                 lockNode->Count++;
  105.  
  106.                 found = TRUE;
  107.  
  108.                 break;
  109.             }
  110.         }
  111.  
  112.         if(!found)
  113.         {
  114.             if(lockNode = AllocMem(sizeof(LockNode),MEMF_PUBLIC | MEMF_ANY | MEMF_CLEAR))
  115.             {
  116.                 AddTail((struct List *)<P_LockList,(struct Node *)lockNode);
  117.  
  118.                 lockNode->Window        = window;
  119.                 lockNode->OldIDCMPFlags    = window->IDCMPFlags;
  120.                 lockNode->Count            = 1;
  121.                 lockNode->MinWidth        = window->MinWidth;
  122.                 lockNode->MaxWidth        = window->MaxWidth;
  123.                 lockNode->MinHeight        = window->MinHeight;
  124.                 lockNode->MaxHeight        = window->MaxHeight;
  125.  
  126.                 WindowLimits(window,window->Width,window->Height,window->Width,window->Height);
  127.  
  128.                 Request(&lockNode->Requester,window);
  129.  
  130.                 /* Now, this needs a bit of explanation. The requester will shut down
  131.                  * menu processing for this window and still we enable IDCMP_MENUPICK.
  132.                  * This is done in order to avoid setting the IDCMP flags to 0. One
  133.                  * side-effect of setting the IDCMP flags to 0 is that the window message
  134.                  * queue will be cleared, which can be undesirable in certain cases.
  135.                  * With the menu strip blocked IDCMP_MENUPICK cannot do any harm.
  136.                  */
  137.  
  138.                 ModifyIDCMP(window,IDCMP_MENUPICK | (window->IDCMPFlags & (IDCMP_REFRESHWINDOW|IDCMP_CHANGEWINDOW)));
  139.  
  140.                 if(V39)
  141.                 {
  142.                     STATIC struct TagItem tags[3] =
  143.                     {
  144.                         WA_BusyPointer,        TRUE,
  145.                         WA_PointerDelay,    TRUE,
  146.  
  147.                         TAG_DONE
  148.                     };
  149.  
  150.                     SetWindowPointerA(window,tags);
  151.                 }
  152.                 else
  153.                 {
  154.                     STATIC UWORD __chip Stopwatch[(1 + 16 + 1) * 2] =
  155.                     {
  156.                         0x0000,0x0000,
  157.  
  158.                         0x0400,0x07C0,
  159.                         0x0000,0x07C0,
  160.                         0x0100,0x0380,
  161.                         0x0000,0x07E0,
  162.                         0x07C0,0x1FF8,
  163.                         0x1FF0,0x3FEC,
  164.                         0x3FF8,0x7FDE,
  165.                         0x3FF8,0x7FBE,
  166.                         0x7FFC,0xFF7F,
  167.                         0x7EFC,0xFFFF,
  168.                         0x7FFC,0xFFFF,
  169.                         0x3FF8,0x7FFE,
  170.                         0x3FF8,0x7FFE,
  171.                         0x1FF0,0x3FFC,
  172.                         0x07C0,0x1FF8,
  173.                         0x0000,0x07E0,
  174.  
  175.                         0x0000,0x0000
  176.                     };
  177.  
  178.                     SetPointer(window,Stopwatch,16,16,-6,0);
  179.                 }
  180.             }
  181.         }
  182.  
  183.         ReleaseSemaphore(<P_LockSemaphore);
  184.     }
  185. }
  186.  
  187.  
  188. /****************************************************************************/
  189.  
  190.  
  191. /****** gtlayout.library/LT_UnlockWindow ******************************************
  192. *
  193. *   NAME
  194. *    LT_UnlockWindow -- The complement to LT_LockWindow().
  195. *
  196. *   SYNOPSIS
  197. *    LT_UnlockWindow(Window);
  198. *                      A0
  199. *
  200. *    VOID LT_UnlockWindow(struct Window *);
  201. *
  202. *   FUNCTION
  203. *    This routine unlocks a window locked using LT_LockWindow, freeing
  204. *    allocated memory, restoring the window characteristics to their
  205. *    original values.
  206. *
  207. *   INPUTS
  208. *    Window - Pointer to window structure; passing NULL is harmless.
  209. *
  210. *   RESULT
  211. *    none
  212. *
  213. *   SEE ALSO
  214. *    gtlayout.library/LT_LockWindow
  215. *
  216. ******************************************************************************
  217. *
  218. */
  219.  
  220. VOID LIBENT
  221. LT_UnlockWindow(REG(a0) struct Window *window)
  222. {
  223.     if(window)
  224.     {
  225.         LockNode *lockNode;
  226.  
  227.         ObtainSemaphore(<P_LockSemaphore);
  228.  
  229.         SCANLIST(<P_LockList,lockNode)
  230.         {
  231.             if(lockNode->Window == window)
  232.             {
  233.                 if(--lockNode->Count < 1)
  234.                     LTP_DeleteWindowLock(lockNode);
  235.  
  236.                 break;
  237.             }
  238.         }
  239.  
  240.         ReleaseSemaphore(<P_LockSemaphore);
  241.     }
  242. }
  243.  
  244.  
  245. /*****************************************************************************/
  246.  
  247.  
  248. /****** gtlayout.library/LT_DeleteWindowLock ******************************************
  249. *
  250. *   NAME
  251. *    LT_DeleteWindowLock -- Remove all locks from a window
  252. *
  253. *   SYNOPSIS
  254. *    LT_DeleteWindowLock(Window);
  255. *                          A0
  256. *
  257. *    VOID LT_DeleteWindowLock(struct Window *);
  258. *
  259. *   FUNCTION
  260. *    Before closing a locked window you should call this routine
  261. *    which will remove all outstanding locks from it.
  262. *
  263. *   INPUTS
  264. *    Window - Pointer to window structure; passing NULL is
  265. *    harmless.
  266. *
  267. *   RESULT
  268. *    none
  269. *
  270. ******************************************************************************
  271. *
  272. */
  273.  
  274. VOID LIBENT
  275. LT_DeleteWindowLock(REG(a0) struct Window *window)
  276. {
  277.     if(window)
  278.     {
  279.         LockNode *lockNode;
  280.  
  281.         ObtainSemaphore(<P_LockSemaphore);
  282.  
  283.         SCANLIST(<P_LockList,lockNode)
  284.         {
  285.             if(lockNode->Window == window)
  286.             {
  287.                 LTP_DeleteWindowLock(lockNode);
  288.                 break;
  289.             }
  290.         }
  291.  
  292.         ReleaseSemaphore(<P_LockSemaphore);
  293.     }
  294. }
  295.